package com.ruoyi.wms.service.impl;

import java.util.List;

import com.ruoyi.common.core.utils.DateUtils;
import com.ruoyi.common.core.utils.MD5Utils;
import com.ruoyi.common.core.utils.StringUtils;
import com.ruoyi.common.security.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.wms.mapper.EndLifeVehicleExtendMapper;
import com.ruoyi.wms.domain.EndLifeVehicleExtend;
import com.ruoyi.wms.service.IEndLifeVehicleExtendService;

/**
 * 报废车辆扩展信息Service业务层处理
 *
 * @author ruoyi
 * @date 2025-10-31
 */
@Service
public class EndLifeVehicleExtendServiceImpl implements IEndLifeVehicleExtendService {
    @Autowired
    private EndLifeVehicleExtendMapper endLifeVehicleExtendMapper;

    /**
     * 查询报废车辆扩展信息
     *
     * @param id 报废车辆扩展信息主键
     * @return 报废车辆扩展信息
     */
    @Override
    public EndLifeVehicleExtend selectEndLifeVehicleExtendById(String id) {
        return endLifeVehicleExtendMapper.selectEndLifeVehicleExtendById(id);
    }

    /**
     * 查询报废车辆扩展信息列表
     *
     * @param endLifeVehicleExtend 报废车辆扩展信息
     * @return 报废车辆扩展信息
     */
    @Override
    public List<EndLifeVehicleExtend> selectEndLifeVehicleExtendList(EndLifeVehicleExtend endLifeVehicleExtend) {
        return endLifeVehicleExtendMapper.selectEndLifeVehicleExtendList(endLifeVehicleExtend);
    }

    /**
     * 新增报废车辆扩展信息
     *
     * @param endLifeVehicleExtend 报废车辆扩展信息
     * @return 结果
     */
    @Override
    public int insertEndLifeVehicleExtend(EndLifeVehicleExtend endLifeVehicleExtend) {
        endLifeVehicleExtend.setId(MD5Utils.md5(endLifeVehicleExtend.getPlateNo()));
        endLifeVehicleExtend.setCreateUser(SecurityUtils.getUsername());
        endLifeVehicleExtend.setCreateDate(DateUtils.getCurrentTime());
        endLifeVehicleExtend.setUpdateDate( DateUtils.getCurrentTime());
        return endLifeVehicleExtendMapper.insertEndLifeVehicleExtend(endLifeVehicleExtend);
    }

    /**
     * 修改报废车辆扩展信息
     *
     * @param endLifeVehicleExtend 报废车辆扩展信息
     * @return 结果
     */
    @Override
    public int updateEndLifeVehicleExtend(EndLifeVehicleExtend endLifeVehicleExtend) {

        int updateResult = 0;
        if (StringUtils.isEmpty(endLifeVehicleExtend.getId())) {
            updateResult = insertEndLifeVehicleExtend(endLifeVehicleExtend);
        }
        endLifeVehicleExtend.setUpdateDate( DateUtils.getCurrentTime());
        updateResult = endLifeVehicleExtendMapper.updateEndLifeVehicleExtend(endLifeVehicleExtend);
        if (0 == updateResult) {
            updateResult = insertEndLifeVehicleExtend(endLifeVehicleExtend);
        }


        return updateResult;



    }

    /**
     * 批量删除报废车辆扩展信息
     *
     * @param ids 需要删除的报废车辆扩展信息主键
     * @return 结果
     */
    @Override
    public int deleteEndLifeVehicleExtendByIds(String[] ids) {
        return endLifeVehicleExtendMapper.deleteEndLifeVehicleExtendByIds(ids);
    }

    /**
     * 删除报废车辆扩展信息信息
     *
     * @param id 报废车辆扩展信息主键
     * @return 结果
     */
    @Override
    public int deleteEndLifeVehicleExtendById(String id) {
        return endLifeVehicleExtendMapper.deleteEndLifeVehicleExtendById(id);
    }
}
